﻿#region Imports
using System;
using System.Drawing;
using System.Windows.Forms;
#endregion

namespace BulkRenamer.Controls
{
    public class BRTextBox : TextBox
    {
        #region Properties
        public FontStyle InitialFontStyle { get; set; }

        public Cursor InitialCursor { get; set; }
        #endregion

        #region Constructors
        public BRTextBox()
            : base()
        {
            InitialFontStyle = this.Font.Style;
            InitialCursor = this.Cursor;

            this.MouseEnter += new EventHandler(BRTextBox_MouseEnter);
            this.MouseLeave += new EventHandler(BRTextBox_MouseLeave);
        }
        #endregion

        #region Formatting events
        private void BRTextBox_MouseEnter(object sender, EventArgs e)
        {
            TextBox txt = (TextBox)sender;
            txt.Focus(); SendKeys.Send("{End}");
            txt.ForeColor = Color.Blue;

            if (Form.ModifierKeys == Keys.Control)
            {
                txt.Font = new Font(txt.Font.FontFamily, txt.Font.Size, FontStyle.Underline, txt.Font.Unit, txt.Font.GdiCharSet);
                txt.Cursor = Cursors.Hand;
            }
        }

        private void BRTextBox_MouseLeave(object sender, EventArgs e)
        {
            TextBox txt = (TextBox)sender;
            txt.ForeColor = Color.Black;

            txt.Font = new Font(txt.Font.FontFamily, txt.Font.Size, InitialFontStyle, txt.Font.Unit, txt.Font.GdiCharSet);
            txt.Cursor = InitialCursor;
        }
        #endregion
    }
}
